home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CAS_Extra.c
-
- Contains: Utility routines for calling CALib.
-
- Written by: Rick Badertscher
-
- Copyright © 1995 ComponentWorks, All rights reserved.
-
- Change History (most recent first):
-
- <7> 05/15/95 RB Added "Container" handler implementations
- <6> 05/13/95 RB Added CAUtil_IsCALibPresent()
- <5> 04/23/95 RB Added Focus handlers
- <4> 04/01/95 RB Added CAWindowActivateHandler()
- <3> 03/30/95 RB Added App_CAFocusLostProc() and App_CAFocusAquiredProc()
- <2> 03/16/95 RB Added Read/Write Wrappers and CASaveDlgHook to
- facilitate the Bento storage model
- <1> 02/21/95 RB Created.
- */
-
-
- #include <Folders.h>
- #include <GestaltEqu.h>
- #include <TextServices.h>
-
-
- #ifdef USE_CALIB
- #include "CALib.h"
- #endif
-
- #include "CAS_Globals.h"
- #include "CAS_App.h"
- #include "CAS_Content.h"
- #include "CAS_Doc.h"
- #include "CAS_Win.h"
- #include "CAS_App.h"
- #include "CAS_ToolPalette.h"
- #include "CAS_Dialog.h"
- #include "CAS_Drag.h"
- #include "CAS_CAUtil.h"
- #include "CAS_StringTools.h"
-
- FileFilterUPP gInsertFilterProc;
-
- pascal Boolean CAUtil_InsertFileFilter (CInfoPBPtr pb);
-
-
- //===========================================================================
- #pragma mark ' Asynchronous Handlers
- //===========================================================================
-
-
- void App_CAErrorHandler (OSErr err, char* mesg)
- {
-
- Str255 errorMsg;
- Str63 errorNumStr;
-
- NumToString (err, errorNumStr);
- sCopyStr("\pCALib Error # ", errorMsg);
- sAppendStr(errorNumStr, errorMsg);
-
- ParamText( errorMsg, nil, nil, nil );
-
- Dialog_CenterALRTonFrontWindow( kErrorDialog );
- StopAlert( kErrorDialog, nil );
-
-
- }
-
-
- //----------------------------------------------------------------------------
- // App_CAFrameShapeRequestHandler
- //
-
- pascal Boolean App_CAFrameShapeRequestHandler ( CADocumentRef document,
- CAFrameRef frameRef,
- RgnHandle rgn)
- {
-
- Boolean modified = false;
- DocPtr theDoc;
- Rect rect;
- ElemPtr elem;
-
- theDoc = CAUtil_GetDocPtr (document);
- elem = Doc_FindElemForFrameRef (theDoc, frameRef);
-
- rect = (**rgn).rgnBBox;
-
- Elem_SetRect (elem, rect);
- modified = true;
-
- return (modified);
-
- }
-
-
- //----------------------------------------------------------------------------
-
-
- WindowPtr App_CAFrontWindowProc(
- CAWindowLayer windowLayer )
- {
-
- switch (windowLayer)
- {
- case kCADocumentWindow:
- return App_GetFrontDocWindow();
-
- case kCAFloatingWindow:
- return ToolPalette_VerifyWindow( nil );
-
- default:
- break;
- }
-
- return nil;
- }
-
- //----------------------------------------------------------------------------
-
- void App_CASelectWindowProc(
- WindowPtr window )
- {
- if ((window == nil) || !Win_IsVisible( window ))
- return;
-
- if (Win_IsFloater( window ))
- ;
- else if (Win_IsAppWindow( window ))
- App_SetFrontDocWindow( window );
- }
-
- //----------------------------------------------------------------------------
-
- Boolean App_CAIsFloaterProc(
- WindowPtr window )
- {
- return Win_IsFloater( window );
- }
-
- //----------------------------------------------------------------------------
-
- WindowPtr App_CAAllocWindowRecProc(
- CAWindowLayer windowLayer )
- {
- switch (windowLayer)
- {
- case kCANoLayer:
- case kCADocumentWindow:
- case kCAFloatingWindow:
- break;
-
- default:
- break;
- }
-
- return nil;
- }
-
- //----------------------------------------------------------------------------
-
- void App_CADisposeWindowRecProc(
- WindowPtr window )
- {
- }
-
- //----------------------------------------------------------------------------
-
- void App_CAFocusAcquiredProc ( CADocumentRef document, CAFocusType focusType)
- {
-
- DocPtr theDoc;
- GrafPtr savePort;
- WindowPtr theWindow = NULL;
-
- theDoc = CAUtil_GetDocPtr (document);
- theWindow = Doc_GetWindow(theDoc);
-
- GetPort (&savePort);
- if (theWindow) SetPort (theWindow);
-
- switch (focusType)
- {
-
- case kCAPrimaryFocus:
-
- // Save the focus document
-
- gFocusDocument = document;
-
- // Set and draw the app menu bar
-
- SetMenuBar (gAppMenuBar);
- DrawMenuBar();
-
- // Invalidate selection regions
-
- CAUtil_InvalSelRgns (theDoc);
-
- break;
-
- default:
- break;
-
- }
-
- SetPort (savePort);
-
- }
-
- //----------------------------------------------------------------------------
-
- void App_CAFocusLostProc ( CADocumentRef document, CAFocusType focusType )
- {
- DocPtr theDoc;
- GrafPtr savePort;
- WindowPtr theWindow = NULL;
-
- theDoc = CAUtil_GetDocPtr (document);
- theWindow = Doc_GetWindow(theDoc);
-
- GetPort (&savePort);
- if (theWindow) SetPort (theWindow);
-
- switch (focusType)
- {
-
- case kCAPrimaryFocus:
-
- gFocusDocument = NULL;
- //Doc_SelectAllElements (theDoc, false);
- CAUtil_InvalSelRgns (CAUtil_GetDocPtr (document));
- break;
-
- default:
- break;
- }
-
- SetPort (savePort);
-
- }
-
- //----------------------------------------------------------------------------
-
- void App_CAWindowActivateHandler (WindowPtr theWindow, Boolean activating)
- {
-
- DocPtr theDoc;
-
- theDoc = (DocPtr)GetWRefCon(theWindow);
-
- if (activating)
- {
- App_Activate (theWindow);
- }
- else
- {
- App_Deactivate (theWindow);
- }
-
- }
-
-
- //----------------------------------------------------------------------------
-
- Boolean App_CAAdjustBorderHandler ( CADocumentRef document,
- CAFrameRef frameRef,
- RgnHandle rgn)
- {
- ElemPtr elem;
- DocPtr theDoc;
- RgnHandle coveredRgn;
- Point location;
-
- theDoc = CAUtil_GetDocPtr (document);
-
- // Clip the active border to any content elements above frameRef in
- // the z-order
-
- elem = Doc_FindElemForFrameRef (theDoc, frameRef);
-
- // compute the covered rgn
- coveredRgn = NewRgn();
- ElemColl_GetRgnOverElem (theDoc->contentColl, elem, coveredRgn);
-
- // subtract the coveredRgn from the active border rgn
- // rgn is in frame coordinates (0 based), so first transform locate it
- // according to frameRef's external transform
-
- Elem_GetLocation (elem, &location);
- OffsetRgn (rgn, location.h, location.v);
- DiffRgn (rgn, coveredRgn, rgn);
-
- // put rgn back in frame coordinates
- OffsetRgn (rgn, -location.h, -location.v);
-
- return (true);
-
- }
-
-
- //===========================================================================
- #pragma mark ' Miscellaneous Utility Routines
- //===========================================================================
-
- //----------------------------------------------------------------------------
-
- pascal short CASaveDialogHook (short item, DialogPtr theDialog, void* userData)
- {
-
- if (item == sfHookFirstCall)
- {
- // Enable the radio button representing the current storage model for this
- // doc
- short currentStorageModel = *((short*)userData);
- ControlHandle theControl;
-
- theControl = (ControlHandle) Dialog_GetItemHandle(theDialog, kNativeRadioItemID);
- if (theControl != nil)
- SetControlValue( theControl, (currentStorageModel == kNativeStorageModel) ? 1 : 0 );
-
- theControl = (ControlHandle) Dialog_GetItemHandle(theDialog, kBentoRadioItemID);
- if (theControl != nil)
- SetControlValue( theControl, (currentStorageModel == kBentoStorageModel) ? 1 : 0 );
-
- }
-
- if ((item == kNativeRadioItemID) || (item == kBentoRadioItemID))
- {
-
- ControlHandle theControl;
-
- theControl = (ControlHandle) Dialog_GetItemHandle(theDialog, kNativeRadioItemID);
- if (theControl != nil)
- SetControlValue( theControl, (item == kNativeRadioItemID) ? 1 : 0 );
-
- theControl = (ControlHandle)Dialog_GetItemHandle( theDialog, kBentoRadioItemID);
- if (theControl != nil)
- SetControlValue( theControl, (item == kBentoRadioItemID) ? 1 : 0 );
-
- *((short*)userData) = (item == kNativeRadioItemID) ? kNativeStorageModel :
- kBentoStorageModel;
-
- return (sfHookNullEvent);
-
- }
-
- return (item);
-
- }
-
-
- //----------------------------------------------------------------------------
-
- OSErr CAUtil_ShutdownCALib()
- {
-
- OSErr theErr;
-
- CAUnregisterWindow (ToolPalette_VerifyWindow(NULL));
- CAShutdown();
- if (theErr = CAError())
- ; // handle the error
-
- // Ignore the error. What would we be able to do about it anyway?
- CloseTSMAwareApplication();
-
- return (theErr);
-
- }
-
- //----------------------------------------------------------------------------
-
- OSErr CAUtil_InitCALib()
- {
- TSMDocumentID kAnyDoc = NULL;
- OSErr err = noErr;
- long gestaltResponse;
-
- if ((err = InitEditionPack()) != noErr)
- {
- DebugStr( "\pInitEditionPack failed" );
- }
-
- // temporary. should always be around in system 7.1 and later.
- if (( (err = Gestalt( gestaltTSMgrVersion, &gestaltResponse)) == noErr) &&
- (gestaltResponse >= 1))
- ;
- else
- DebugStr( "\pTSM not available. This is unexpected." );
-
- if ((err = InitTSMAwareApplication()) != noErr)
- {
- DebugStr("\pInitTSMAwareApplication failed");
-
- ExitToShell();
- }
-
- if (UseInputWindow(kAnyDoc, true) != noErr)
- DebugStr( "\pUseInputWindow failed. Bizarrrrrre." );
-
- CAInit();
-
- CASetErrorProc( (CAErrorProc) App_CAErrorHandler );
-
- if ((err = CAError()) != noErr)
- ; // handle the error
-
-
- return (err);
-
- }
-
-
-
- //----------------------------------------------------------------------------
-
- OSErr CAUtil_ReadWrapper (IOStreamPtr ioStream, Ptr buffer, long* length)
- {
-
- OSErr theErr = noErr;
- DocPtr theDoc;
-
- theDoc = ioStream->theDoc;
-
- if (ioStream->type == fileStream)
- {
- if (theDoc->storageModel == kBentoStorageModel)
- {
- CARead(theDoc->partDocRef, buffer, (CASize*) length );
- return (CAError());
- }
- else
- {
- theErr = FSRead( theDoc->fileRefNum, length, buffer);
- }
- }
- else
- {
- BlockMove (ioStream->buffer, buffer, *length);
- ioStream->buffer = (Ptr) ioStream->buffer + *length;
-
- }
-
- return (theErr);
-
- }
-
- //----------------------------------------------------------------------------
-
- OSErr CAUtil_WriteWrapper (IOStreamPtr ioStream, Ptr buffer, long* length)
- {
-
- OSErr theErr = noErr;
- DocPtr theDoc;
-
- theDoc = ioStream->theDoc;
-
- if (ioStream->type == fileStream)
- {
- if (theDoc->storageModel == kBentoStorageModel)
- {
- CAWrite(theDoc->partDocRef, buffer, (CASize*) length );
- return (CAError());
-
- }
- else
- {
- theErr = FSWrite( theDoc->fileRefNum, length, buffer);
- }
- }
- else
- {
- BlockMove (buffer, ioStream->buffer, *length);
- ioStream->buffer = (Ptr) ioStream->buffer + *length;
- }
- return (theErr);
-
- }
-
- //----------------------------------------------------------------------------
-
- OSErr CAUtil_WriteTo (CADocumentRef doc, Ptr buffer, long* length)
- {
- CAWrite(doc, buffer, (CASize*) length );
- return (CAError());
- }
-
- //----------------------------------------------------------------------------
-
- Boolean CAUtil_IsCALibPresent ()
- {
-
- Boolean present = false;
-
- // As per the CALib pre-alpha code review.
-
-
- if (CAInit != NULL)
- {
- present = true;
- }
-
- return (present);
-
- }
-
- //---------------------------------------------------------------------------
- void CAUtil_PartInfoMenu (DocPtr theDoc)
- {
- short i, count;
- ElemPtr elem;
-
- count = ElemColl_GetCount (theDoc->contentColl);
-
- for (i=1; i <= count; i++)
- {
- elem = ElemColl_GetNthElem (theDoc->contentColl, i);
- if (Elem_GetSelected (elem) && (Elem_GetType (elem) == kFrameElemType))
- {
- CAShowPartFrameInfo(theDoc->partDocRef,
- CAGetVisFrame(theDoc->partDocRef, (CAFrameRef) elem->elemData));
- }
- }
-
- }
-
-
- //---------------------------------------------------------------------------
- void CAUtil_OpenSelectionMenu (WindowPtr theWindow)
- {
- short i, count;
- DocPtr theDoc;
- ElemPtr elem;
-
- // if there is no window or it's not ours, get out.
- if (Win_IsAppWindow( theWindow ))
- {
- theDoc = (DocPtr)GetWRefCon( theWindow );
- }
-
- count = ElemColl_GetCount (theDoc->contentColl);
-
- for (i=1; i <= count; i++)
- {
- elem = ElemColl_GetNthElem (theDoc->contentColl, i);
- if (Elem_GetSelected (elem) && (Elem_GetType (elem) == kFrameElemType))
- {
- CAViewFrameInWindow(theDoc->partDocRef, (CAFrameRef) elem->elemData);
- }
- }
-
-
- }
-
-
-
- //---------------------------------------------------------------------------
-
- void CAUtil_InsertMenu (WindowPtr theWindow)
- {
- SFReply sfReply;
- WindowPtr frontWindow;
- CADocumentRef insertDoc;
- DocPtr theDoc;
- CADocumentRef document;
- CAFrameRef newFrameRef;
- Rect dlogRect;
- Rect rScreen;
- ElemPtr elem;
-
- // if there is no window or it's not ours, get out.
- if (Win_IsAppWindow( theWindow ))
- {
- theDoc = (DocPtr)GetWRefCon( theWindow );
- }
-
- document = theDoc->partDocRef;
-
- gInsertFilterProc = NewFileFilterProc(CAUtil_InsertFileFilter);
-
- frontWindow = CAGetFrontDocWindow();
- if (!CARequestModalFocus( frontWindow))
- return;
-
- dlogRect.left = 0; dlogRect.top = 0;
- dlogRect.right = 136; dlogRect.bottom = 136;
-
- GetMainScreenRect( &rScreen );
- rScreen.top += GetMBarHeight() + 4;
-
- rCenterRectInRect( &rScreen, &dlogRect );
-
- SFGetFile( (*((Point*) &dlogRect)), "\p",
- (FileFilterUPP) gInsertFilterProc, -1,
- NULL,
- (DlgHookUPP) NULL,
- &sfReply);
-
- CARelinquishModalFocus( frontWindow );
-
- if (sfReply.good)
- {
- CACloneKey key;
- CATransform extTransform;
- FSSpec insertFIle;
-
- FSMakeFSSpec (sfReply.vRefNum, 0, sfReply.fName, &insertFIle);
-
- insertDoc = CAOpenDocument (&insertFIle, NULL, 0, 0);
-
- key = CABeginClone (insertDoc, document, kCACloneAll);
- newFrameRef = CACloneFrameRef (NULL, insertDoc, document, true, key);
- CAEndClone (insertDoc, document, key);
-
- CACloseDocument (insertDoc);
-
- elem = Doc_AddEmbeddedFrame (theDoc, newFrameRef, theDoc->insertionPoint);
-
- // Create a facet for the new frame
- Elem_SetVisible (elem, true);
-
- Doc_SelectAllElements (theDoc, false);
- Elem_SetSelected (elem, true);
-
- Doc_SetDirty( theDoc, true );
-
- }
-
-
- return;
-
- }
-
-
- //--------------------------------------------------------------------
- // CAUtil_InsertFileFilter
- //--------------------------------------------------------------------
-
- pascal Boolean CAUtil_InsertFileFilter (CInfoPBPtr pb)
- {
- HFileInfo* fpb = (HFileInfo*)pb;
-
- if (!(fpb->ioFlAttrib & 16))
- {
- if ((fpb->ioFlFndrInfo.fdCreator == kODShellSignature) &&
- (fpb->ioFlFndrInfo.fdType != 'APPL') &&
- (fpb->ioFlFndrInfo.fdType != 'shlb'))
- {
- return false;
- }
- }
-
- return true;
- }
-
-
-
- //----------------------------------------------------------------------------
-
- void CAUtil_InvalSelRgns (DocPtr theDoc)
- {
- short i;
- short count;
- ElemPtr elem;
-
- count = ElemColl_GetCount (theDoc->contentColl);
- for (i=1; i <= count; i++)
- {
-
- elem = ElemColl_GetNthElem (theDoc->contentColl, i);
- Elem_InvalSelRgn (elem);
- }
-
- ElemColl_ClipElements(theDoc->contentColl, NULL);
-
- }
-
-
- //----------------------------------------------------------------------------
-
- DocPtr CAUtil_GetDocPtr (CADocumentRef document)
- {
- WindowPtr curFrontW;
- DocPtr theDoc = NULL;
-
- curFrontW = (WindowPtr)LMGetWindowList();
- while (curFrontW != nil)
- {
- if (!Win_IsFloater( curFrontW ) &&
- Win_IsAppWindow( curFrontW) && !Win_IsToolWindow(curFrontW))
- {
- theDoc = (DocPtr)GetWRefCon( curFrontW );
- if (theDoc->partDocRef == document) break;
- theDoc = NULL;
- }
-
- curFrontW = (WindowPtr)(((WindowPeek)curFrontW)->nextWindow);
-
- }
-
- return theDoc;
-
-
- }
-
-
- //----------------------------------------------------------------------------
-
- Boolean CAUtil_HandleMouseDownBorder ( EventRecord* theEvent,
- CAEventInfo* eventInfo)
- {
- WindowPtr theWindow;
- short windowCode;
- DocPtr theDoc;
- Boolean handled = false;
- ElemPtr elem;
- GrafPtr savePort;
-
- windowCode = FindWindow( theEvent->where, &theWindow );
-
- GetPort (&savePort);
- SetPort (theWindow);
-
- if (windowCode == inContent)
- {
- theDoc = (DocPtr)GetWRefCon( theWindow );
-
- elem = Doc_FindElemForFrameRef (theDoc, eventInfo->embeddedFrame);
-
- if (elem)
- {
-
- CARequestStandardFocusSet(theWindow);
-
- // Bring to front and select
- ElemColl_MoveElemToFront(theDoc->contentColl, elem);
- Doc_SelectAllElements( theDoc, false );
- Elem_SetSelected (elem, true);
-
- // Redraw
- Win_Update (theWindow);
-
- // Do a drag
- Drag_DragItem( theWindow, theEvent);
-
-
- }
-
- handled = true;
-
-
- }
-
- SetPort (savePort);
-
- return (handled);
-
- }
-
-
- //----------------------------------------------------------------------------
-
- Boolean CAUtil_HandleMouseDownEmbedded ( EventRecord* theEvent,
- CAEventInfo* eventInfo)
- {
- WindowPtr theWindow;
- Point docPt;
- short windowCode;
- short elemCode;
- DocPtr theDoc;
- Boolean handled = false;
- ElemPtr elem;
- Point saveOrigin;
- GrafPtr savePort;
-
- windowCode = FindWindow( theEvent->where, &theWindow );
- theDoc = ((DocPtr)GetWRefCon(theWindow));
-
- GetPort( &savePort );
- SetPort( theWindow );
-
- // Compute the mouse in doc coords.
- docPt = theEvent->where;
- GetOrigin( &saveOrigin );
- Doc_SetGrafOrigin( theDoc );
- GlobalToLocal( &docPt );
- SetOrigin( saveOrigin.h, saveOrigin.v );
-
- if (windowCode == inContent)
- {
-
- elemCode = ElemColl_FindElem(theDoc->contentColl, docPt, &elem);
-
- if (elem)
- {
-
- switch (elemCode)
- {
-
- case inElement:
-
- Elem_HandleMouseDown (elem, theDoc, theEvent);
- SetRectRgn( gMouseRgn, 0, 0, 1, 1 );
- handled = true;
- break;
- case inCornerResize:
- break;
- case inEdgeResize:
- break;
-
- }
-
- }
-
-
- }
-
- SetPort( savePort );
-
- return (handled);
-
-
- }
-
- //----------------------------------------------------------------------------
- Boolean CAUtil_HandleMouseUpEmbedded ( EventRecord* theEvent,
- CAEventInfo* eventInfo)
- {
- WindowPtr theWindow;
- short windowCode;
- Boolean handled = false;
-
- windowCode = FindWindow( theEvent->where, &theWindow );
-
- if (theWindow != App_GetFrontDocWindow())
- {
- App_SetFrontDocWindow (theWindow);
- handled = true;
- }
-
- return (handled);
-
-
- }
-
-
-
- //---------------------------------------------------------------------------
- void CAUtil_EmbedODContainerFromCADocument (DocPtr theDoc, CADocumentRef document, Point location)
- {
- CACloneKey key;
- CAFrameRef newFrameRef;
- CATransform extTransform;
- ElemPtr elem;
- Rect theRect;
- RgnHandle theRgn;
- Point adjustedLocation;
-
- // Clone the root part from the container doc
-
- key = CABeginClone (document, theDoc->partDocRef, kCACloneAll);
- newFrameRef = CACloneFrameRef (NULL, document, theDoc->partDocRef, true, key);
- CAEndClone (document, theDoc->partDocRef, key);
-
- Doc_SelectAllElements (theDoc, false);
-
- elem = Doc_AddEmbeddedFrame (theDoc, newFrameRef, location);
-
- // Create a facet for the new frame
-
- Elem_SetVisible (elem, true);
-
- ElemColl_MoveElemToFront(theDoc->contentColl, elem);
- Doc_SelectAllElements (theDoc, false);
- Elem_SetSelected (elem, true);
-
- Doc_SetDirty( theDoc, true );
-
-
- }
-
- //---------------------------------------------------------------------------
- Boolean CAUtil_ScrapHasType (ResType type, long* scrapOffset, long* length)
- {
- long scrapLength;
- Boolean retval = false;
-
- scrapLength = GetScrap( NULL, type, scrapOffset );
- *length = scrapLength;
-
- if (scrapLength >= 0)
- {
- retval = true;
- }
-
- return (retval);
-
- }
-
-
-
-
- void CAUtil_CreateDocFileFromSelection (DocPtr theDoc, FSSpec* fsSpec)
- {
- CACloneKey key = NULL;
- OSErr theErr = noErr;
- CADocumentRef newDoc;
- short count, i;
- ElemPtr elem;
- DocPtr tempDoc;
- FInfo fndrInfo;
- CAFrameRef newFrameRef;
-
- // Create a new CASample document
- tempDoc = (DocPtr)NewPtrClear( (long)sizeof(DocRecord) );
- Doc_InitData( tempDoc );
-
- FSpCreate (fsSpec, kOurFileCreator, kContainerFileType, 0 );
- tempDoc->fileSpec = *fsSpec;
-
- // Create the CADocument (Don't bind to a file until save time)
- newDoc = CACreateDocument(NULL, NULL);
-
- // Set tempDoc's CADocument reference
- tempDoc->partDocRef = newDoc;
- tempDoc->storageModel = kBentoStorageModel;
-
- // Clone each selected element
-
- count = ElemColl_GetCount (theDoc->contentColl);
-
- for (i=1; i <= count; i++)
- {
- elem = ElemColl_GetNthElem (theDoc->contentColl, i);
- if (Elem_GetSelected (elem))
- {
- ElemPtr clonedElem;
-
- // Add the element
- clonedElem = Elem_Clone (elem);
- ElemColl_AddElem (tempDoc->contentColl, clonedElem);
-
- #ifdef USE_CALIB
- // Clone the frame if the element is a frame
- if (elem->elemType == kFrameElemType)
- {
-
- if (!key)
- key = CABeginClone (theDoc->partDocRef, tempDoc->partDocRef, kCACloneCopy);
-
- newFrameRef = CACloneFrameRef ((CAFrameRef)elem->elemData, theDoc->partDocRef,
- tempDoc->partDocRef, false, key);
-
- clonedElem->elemData = (Handle) newFrameRef;
-
- }
- #endif
-
- }
- }
-
- #ifdef USE_CALIB
- // End the clone
- if (key)
- CAEndClone (theDoc->partDocRef, tempDoc->partDocRef, key);
- #endif
-
- Doc_WriteFile (tempDoc);
- Doc_Close( tempDoc );
-
- // close the file (if it exists)
- if (tempDoc->fileRefNum != 0)
- theErr = FSClose( tempDoc->fileRefNum );
-
- DisposePtr ((Ptr)tempDoc);
-
- return;
-
-
- }
-
-
- OSErr CAUtil_AddItemsFromDocFile(
- DocPtr theDoc,
- FSSpecPtr fsSpec,
- Point* origin)
- {
-
- CACloneKey key = NULL;
- CADocumentRef sourceDoc;
- DocPtr tempDoc;
- OSErr err;
- short count, i;
- ElemPtr elem, newElem;
- CAFrameRef newFrameRef;
- Point location;
- ElemCollPtr tempColl;
- Rect boundsRect;
-
- // Create list to hold transfer elemPtr's
- tempColl = (ElemCollPtr) NewPtr (sizeof (ElemColl));
- ElemColl_Init (tempColl, NULL);
-
- // Create a new CASample document
- tempDoc = (DocPtr)NewPtrClear( (long)sizeof(DocRecord) );
- Doc_InitData( tempDoc );
-
- // Setup for the read
- tempDoc->fileSpec = *fsSpec;
-
- err = FSpOpenDF( fsSpec, fsRdWrPerm, &tempDoc->fileRefNum );
- if (err == noErr)
- tempDoc->fileLocked = false;
- else if (err == permErr)
- {
- // open the data fork (read-only)
- tempDoc->fileLocked = true;
- err = FSpOpenDF( fsSpec, fsRdPerm, &tempDoc->fileRefNum );
- }
-
- // Read it in
- err = Doc_ReadFile( tempDoc );
- if (err) DebugStr ("\pError Doc_ReadFile");
-
- // Compute the bounds rect of the content
- Doc_CalcContentBounds(tempDoc, &boundsRect);
-
- // Copy each element from tempDoc into theDoc
- count = ElemColl_GetCount (tempDoc->contentColl);
-
- for (i=1; i<= count; ++i)
- {
-
- // Clone the content element
- elem = ElemColl_GetNthElem (tempDoc->contentColl, i);
- newElem = Elem_Clone (elem);
- ElemColl_AddElem (theDoc->contentColl, newElem);
- ElemColl_AddElemTemp (tempColl, newElem);
-
- #ifdef USE_CALIB
- // Clone the CAFrame if needed
- if (newElem->elemType == kFrameElemType)
- {
-
- if (!key)
- key = CABeginClone (tempDoc->partDocRef, theDoc->partDocRef, kCACloneCopy);
-
- newFrameRef = CACloneFrameRef ((CAFrameRef)elem->elemData, tempDoc->partDocRef,
- theDoc->partDocRef, false, key);
-
- newElem->elemData = (Handle) newFrameRef;
-
- }
- #endif
-
- // Set the new location
- Elem_GetLocation (newElem, &location);
- if (origin)
- {
- location.h = location.h - boundsRect.left + (*origin).h;
- location.v = location.v - boundsRect.top + (*origin).v;
- }
- Elem_SetLocation (newElem, location);
-
- }
-
-
- #ifdef USE_CALIB
- // End the clone
- if (key)
- CAEndClone (tempDoc->partDocRef, theDoc->partDocRef, key);
- #endif
-
- // Close the document
- Doc_Close( tempDoc );
-
- // close the file (if it exists)
- if (tempDoc->fileRefNum != 0)
- err = FSClose( tempDoc->fileRefNum );
-
- DisposePtr ((Ptr)tempDoc);
-
- count = ElemColl_GetCount (tempColl);
- for (i = 1; i<= count; ++i)
- {
- elem = ElemColl_GetNthElem (tempColl, i);
-
- // Set visible and select
- Elem_SetVisible (elem, true);
- Elem_SetSelected (elem, true);
- }
-
- ElemColl_Free (tempColl);
- DisposePtr ((Ptr) tempColl);
-
- Doc_SetDirty( theDoc, true );
-
- return (err);
-
- }
-
-
-
-